#!/usr/bin/perl -w
#
# Copyright(c) Plink Limited 2006. All rights reserved.
#
# $Header:$
#
# $Log:$
# 
# Author:      Jeremy Banks
#
# Description: The main executable
#

#----------------------------------------------------------------------
# External Modules
#----------------------------------------------------------------------

use strict;

use Getopt::Long;

use XMLTV::Configuration;
use XMLTV::Logger;
use XMLTV::Settings;

#---------------------------------------------------------------------------
# Globals
#---------------------------------------------------------------------------

my $version = 0.1;
my $longestShowPeriod = 360;
my $script_name = $0;
$script_name =~ s/.*\///;
my $output_file;
my $rss;
my $channels;
XMLTV::Logger->log_dir(XMLTV::Settings->log_dir());
my $logger = XMLTV::Logger->instance();
my $start = time;

main();

#---------------------------------------------------------------------------
# Main
#---------------------------------------------------------------------------

sub main
{
   get_options();
   my $configuration = XMLTV::Configuration->new();
}

#---------------------------------------------------------------------------
# Start up the log file
#---------------------------------------------------------------------------

sub start_log
{
   $logger->log("xmltv v$version", 1);
   $logger->log("output file: " . $output_file, 1);
   $logger->log("rss feed: " . $rss, 1);
   $logger->log("channels: " . (join " ", @{$channels}), 1);
}

#---------------------------------------------------------------------------
# Get command line options
#---------------------------------------------------------------------------

sub get_options
{
   GetOptions("out=s" => \$output_file,
              "rss=s" => \$rss);
   $channels = \@ARGV;
   usage("No rss feed") unless $rss;
   usage("No output file") unless $output_file;
   usage("No channels") unless scalar @{$channels};

   start_log();
   XMLTV::Settings::rss_feed($rss);
}

#---------------------------------------------------------------------------
# Usage
#---------------------------------------------------------------------------

sub usage
{
   my $msg = shift;
   die <<END;
$msg

Usage: $script_name -out <output xml file> -rss <rss feed url> -- channel1 channel2...
END
}
